﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GsifWeb4.Models;
using System.Web.Mvc;

namespace GsifWeb4.ViewModels
{
    public class MatchesToEditViewModel
    {
        public List<int> Years { get; set; }
        public List<match_gsif> Matches { get; set; }
        public laget_gsif LoggedInPlayer { get; set; }

        public MatchesToEditViewModel(string loggedInUserName, gsifdbEntities gsifDB, int year)
        {
            // Get all years for where there had been matches
            Years = (from allmatches in gsifDB.match_gsif
                               where allmatches.Datum.HasValue
                               select allmatches.Datum.Value.Year).Distinct().OrderByDescending(y => y).ToList();

            Matches = (from matches in gsifDB.match_gsif
                       where matches.Datum.HasValue && matches.Datum.Value.Year == year
                       select matches).ToList();
                        
            LoggedInPlayer = (from player in gsifDB.laget_gsif
                              where player.Anvandarnamn == loggedInUserName
                              select player).SingleOrDefault();
        }
    }
}